using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;

namespace MeetingRoom.Data.Implementation
{
    public class MeetingRoomDao
    {
        protected ISessionFactory sessionFactory = null;

        public MeetingRoomDao()
        {
            Configuration config = new Configuration();
            config.AddClass(typeof(MeetingRoom.Domain.MeetingRoom));
            config.AddClass(typeof(MeetingRoom.Domain.MeetingRoomType));
            config.AddClass(typeof(MeetingRoom.Domain.MeetingRoomStatus));

            this.sessionFactory = config.BuildSessionFactory();
        }

        public MeetingRoom.Domain.MeetingRoom Create(MeetingRoom.Domain.MeetingRoom meetingRoom)
        {
            using (ISession session = this.sessionFactory.OpenSession())
            {
                using (ITransaction tx = session.BeginTransaction())
                {
                    session.Save(meetingRoom);
                    tx.Commit();
                }
            }

            return meetingRoom;
        }
    }
}
